package com.lesso.yjy.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.yjy.sunflower.domain.repository.EmployeeRepository;
import com.lesso.yjy.sunflower.infra.assembler.EmployeeAssembler;
import com.lesso.yjy.sunflower.pojo.dto.EmployeeDTO;
import com.lesso.yjy.sunflower.pojo.dto.EmployeeQueryDTO;
import com.lesso.yjy.sunflower.pojo.vo.EmployeeVO;
import org.springframework.stereotype.Service;

@Service
public class EmployeeDomainService {
    private final EmployeeRepository employeeRepository;

    public EmployeeDomainService(EmployeeRepository employeeRepository) {
        this.employeeRepository = employeeRepository;
    }

    public Long save(EmployeeDTO dto) {
        return employeeRepository.save(EmployeeAssembler.INSTANCE.dtoToEntity(dto));
    }

    public Page<EmployeeVO> page(EmployeeQueryDTO dto) {
        return employeeRepository.getPageList(dto);
    }

    public Page<EmployeeVO> customPage(EmployeeQueryDTO dto) {
        return employeeRepository.getCustomPageList(dto);
    }

    public void deleteById(Long id) {
        employeeRepository.removeById(id);
    }

    public void update(EmployeeDTO dto) {
        employeeRepository.updateById(dto);
    }
    public EmployeeVO getBy(Long id) {
        return employeeRepository.getById(id);
    }
}
